function varargout = interpCrossingData(p1, p2, C, mu)

%This is a special interpolator for a specific proboem that comes up when
%computing Poincare sections of the planar CRTBP.  The problem comes up
%when trajectories pass too close to the singularities at -mu and 1-mu 
%(see comments in 'CRTBPpoincare.m').  

%Some of the signs and operations used here only make sense in the context
%of the specific problem: This is not a general quadratic interpolator.

x1=p1(2);
x2=p2(2);
yx1=p1(1);
s1=-p1(4);
s2=-p2(4);

a=(s2-s1)/(x2-x1);
b=s1-2*a*x1;
c=yx1-a*x1^2-b*x1;

m=-b;
theta=atan(-1/b);
r=magnitudeVelocity([c; 0; 0],C, mu);

xCrossing=c;
xdot=r*cos(theta);
ydot=r*sin(theta);

varargout(1,1)={xCrossing};
varargout(1,2)={xdot};
varargout(1,3)={ydot};